// @ts-nocheck
import React, { useEffect, useState } from "react";
import { Avatar, Button } from "antd-mobile";
import { useNavigate } from "react-router-dom";
import "./index.less";
import { getCurrentUserInfo } from "@/utils/authority";
import { getMessageList } from "./service";

const User: React.FC<any> = () => {
	const navigate = useNavigate();
	const userId = getCurrentUserInfo()?.data?.id;
	const [list, setList] = useState([]);
	const getListData = async () => {
		const params = {
			userId: userId,
		};
		try {
			const { data } = await getMessageList(params);
			setList(data || []);
		} catch {}
	};

	useEffect(() => {
		getListData();
	}, []);
	const goDetails = (val) => {
		switch (val?.type) {
			case 1:
				navigate("/user/trends/communityReplyDetails", { state: val });
				break;
			case 2:
				navigate("/user/trends/MyActivityDetails", { state: val });
				break;
			case 3:
				navigate("/user/trends/historyReportDetails", { state: val });
				break;

			default:
				break;
		}
	};

	return (
		<div className="message-contarnier">
			<div className="header">
				<p>消息</p>
			</div>
			<div className="message-box">
				{list.map((item) => (
					<div
						className="message-box-card"
						key={item.id}
						onClick={() => goDetails(item)}>
						<div className="message-box-card-title">
							<div>{item?.title || ""}</div>
							<div className={item?.type == 1 ? "service" : item?.type == 2 ? "event" : "history"}>{item?.typename}</div>
						</div>
						<div className="message-box-card-time">{item?.time || ""}</div>
					</div>
				))}
			</div>
		</div>
	);
};

export default User;
